//
//  stViewController.m
//  第四次考试
//
//  Created by 田宇 on 15/8/14.
//  Copyright (c) 2015年 田宇. All rights reserved.
//

#import "stViewController.h"
#import "hhTableViewCell.h"
#import "webViewController.h"
#define ID 4;
#define Height 90;
@interface stViewController ()

@end

@implementation stViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    
//    NSString *arr;
//    int i = 3;
//    int j = 5;
//    arr = j>i?@"大于":@"小于";
    
    // Do any additional setup after loading the view from its nib.
    _arry =@[@{@"headertitle":@"我是header",
               @"footertitle":@"我是footer",
               @"fist":@[@{@"title":@"我是大A",
                           @"date":@"111"},
                         @{@"title":@"我是大A",
                           @"date":@"111"}
                         ]
               },
             @{@"headertitle":@"我是header",
               @"footertitle":@"我是footer",
               @"fist":@[@{@"title":@"我是大A",
                           @"date":@"111"},
                         @{@"title":@"我是大A",
                           @"date":@"111"}
                         ]
               }
             ];
//    [[NSUserDefaults standardUserDefaults]setObject:@"tianyu" forKey:@"name"];
//    NSString *name=[[NSUserDefaults standardUserDefaults]valueForKey:@"name"];
//    [[NSUserDefaults standardUserDefaults]removeObjectForKey:name];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

-(UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section{
    UIView *headerview= [[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
    headerview.backgroundColor=[UIColor grayColor];
    UILabel *label=[[UILabel alloc ]initWithFrame:CGRectMake(10, 10, 300, 30)];
    NSDictionary *big =[_arry objectAtIndex:section];
  label.text=big[@"headertitle" ];
    
    [headerview addSubview:label];
    return headerview;
}
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{
    return 60;
}
-(UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section{
    UIView *footerview=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 320, 60)];
    footerview.backgroundColor=[UIColor redColor];
    UILabel *label=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 300, 30)];
    NSDictionary *big =[_arry objectAtIndex:section];
    label.text=big[@"footertitle"];
    [footerview addSubview:label];
    return footerview;
}
-(CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section{
    return 60;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    NSString *indentifier=@"hhTableViewCell";
    hhTableViewCell *cell=[tableView dequeueReusableHeaderFooterViewWithIdentifier:indentifier];
    if (cell ==nil) {
        cell=[[[NSBundle mainBundle] loadNibNamed:@"hhTableViewCell" owner:self options:nil]lastObject];
    }
//    hhTableViewCell *cell = [[[NSBundle mainBundle] loadNibNamed:@"hhTableViewCell" owner:self options:nil]lastObject];
    
    NSDictionary *big=[_arry objectAtIndex:indexPath.section];
    NSArray *bug=big[@"fist"];
    NSDictionary *pig=[bug objectAtIndex:indexPath.row];
    cell.titlelabel.text=pig[@"title"];
    cell.datelabel.text=pig[@"date"];
    
    
    return cell;
}
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    NSDictionary *dic=[_arry objectAtIndex:section];
    NSArray *adic=dic[@"fist"];
    return adic.count;
}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 90;
}
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView{
    return _arry.count;
}

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
}
-(void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    
}
-(void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
}

-(void)viewDidDisappear:(BOOL)animated{
    [super viewDidDisappear:animated];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    webViewController *va=[[webViewController alloc]init];
    [self.navigationController pushViewController: va animated:YES];
    UIAlertView *alrt = [[UIAlertView alloc] initWithTitle:@"提示" message:@"确定要退出吗？" delegate:self cancelButtonTitle:@"取消" otherButtonTitles:@"确定", nil];
    [alrt show];
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
